/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package se.bth.ke.firstfriend.dto;

import java.util.List;
import se.bth.ke.firstfriend.model.Article;
import se.bth.ke.firstfriend.model.Topic;

/**
 *
 * @author nico.rehwaldt
 */
public class EditArticleDTO {

    private Article article;
    private String topicsString;
    private boolean isUpdate = false;

    public EditArticleDTO() {}

    public EditArticleDTO(Article article) {
        this.article = article;
    }
    
    public EditArticleDTO(Article article, List<Topic> topics) {
        this(article);
        this.topicsString = getTopicsInternal(topics);
    }

    public EditArticleDTO(Article article, String topicsString) {
        this(article);
        this.topicsString = topicsString;
    }

    public String getTopics() {
        return topicsString;
    }

    private String getTopicsInternal(List<Topic> topics) {
        StringBuilder builder = new StringBuilder();
        for (Topic t: topics) {
            builder.append(builder.length() > 0 ? ", " : "")
                   .append(t.getName());
        }

        return builder.toString();
    }

    public String getTitle() {
        return article.getTitle();
    }

    public String getContent() {
        return article.getContent();
    }

    public Long getId() {
        return article.getId();
    }

    public EditArticleDTO markAsUpdate() {
        this.isUpdate = true;
        return this;
    }

    public boolean isUpdate() {
        return isUpdate;
    }
}
